package ru.spbu.math.android.cbrf.model;

import java.util.Comparator;

public class Category {
	
	private String name;
	
	public String getName(){
		return name;
	}
	
	public Category(String name) {
		this.name = name;
	}
	
  	@Override
    public boolean equals(Object o) {
	
    	if (o == null) {
    		return false;
    	}
    	
    	try {
			Category category = (Category) o;
			if (this.name.equals(category.getName())) {
				return true;
			} else {
				return false;
			}
		} catch (ClassCastException e) {
			return false;
		}    	
    }
  	
  	@Override
    public int hashCode() {
    	return name.hashCode();
    }

  	public static Comparator<Category> getComparator() {
    	return new CategoryComparator();
    }
    
    private static class CategoryComparator implements Comparator<Category> {

		@Override
		public int compare(Category object1, Category object2) {
			return object1.getName().compareTo(object2.getName());
		}
    }
}
